package com.example.demo.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.demo.entity.City;
import com.example.demo.service.ICityService;
import com.example.demo.service.IUserService;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2017/6/16.
 */

@RestController
@RequestMapping("/city")
public class CityController {

    @Autowired
    private ICityService cityService;


    @GetMapping("/add")
    public Object add() throws JSONException {

        City city =  new City();
        city.setId(888);
        city.setName("哈尔滨");
        city.setProvinceId(10);
        boolean  suc = cityService.insert(city);
        return suc;
    }


    @GetMapping("/query")
    public Object query() throws JSONException {
        //http://mp.baomidou.com/#/quick-start
        EntityWrapper wrapper = new EntityWrapper<City>();
        wrapper.eq("name","广州市");
        Page<City> userList = cityService.selectPage(
                new Page<City>(1, 10), wrapper
        );
        return userList;
    }

    @GetMapping("/queryProvince")
    public Object queryProvince(int cityId) throws JSONException {
        //http://mp.baomidou.com/#/quick-start
        return  cityService.getProvinceName(cityId);
    }
}
